package com.cskaoyan.controller;

import com.cskaoyan.bean.AdminListRespVo;
import com.cskaoyan.bean.WxFootprintListBean;
import com.cskaoyan.bean.params.BaseParam;
import com.cskaoyan.service.WxFootprintService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @USER: cuiweiguo#
 * @DATE: 2022/5/8
 * @TIME: 22:13
 * @PROJECT_NAME: mallproject2
 */
@RestController
@RequestMapping("wx/footprint")
public class WxFootprintController {

    @Autowired
    WxFootprintService wxFootprintService;

    @RequestMapping("list")
    public AdminListRespVo<WxFootprintListBean> list(BaseParam baseParam) {
        //http://182.92.235.201:8083/wx/footprint/list?page=1&limit=10
        //get
        //TODO:这里仍然有个userId需要传入
        Subject subject = SecurityUtils.getSubject();
        Integer userId = (Integer) subject.getPrincipals().getPrimaryPrincipal();

        //Integer userId = 1;
        WxFootprintListBean wxFootprintListBean = wxFootprintService.list(userId,baseParam);

        return AdminListRespVo.listOk(wxFootprintListBean);
    }

    @PostMapping("delete")
    public AdminListRespVo<WxFootprintListBean> delete(@RequestBody Map map) {
        Integer id = (Integer) map.get("id");
       int code = wxFootprintService.delete(id);
       if (code==200){
           return AdminListRespVo.listOk("null");
       }
        return null;
    }

}
